package cn.tm.liu.mode.factory.demo1;

/**
 * @author Marvin.L
 * @description
 * @date 2022.04.09 13.41
 */
public class ComputerFactory {

    private ComputerFactory() {
    }

    private static ComputerFactory factory;

    public static ComputerFactory getInstance() {
        synchronized (ComputerFactory.class) {
            if (null == ComputerFactory.factory) {
                synchronized (ComputerFactory.class) {
                    if (null == ComputerFactory.factory)
                        ComputerFactory.factory = new ComputerFactory();
                }
            }
        }
        return ComputerFactory.factory;
    }

    public Computer getComputer(String type, String ram, String hdd, String cpu) {

        switch (type) {
            case "PC":
            case "pc":
                return new PC(ram, hdd, cpu);
            case "Server":
            case "server":
                return new Server(ram, hdd, cpu);
            default:
                return null;
        }
    }

}
